package com.bdv.md.model;

import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

@Entity
@Table (name = "transaction_history")
@DynamicInsert
@DynamicUpdate
public class TransHistory extends BaseObject {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4L;
	private Integer txHistoryId;
	private Timestamp recordTime;
	private String txId;
	private String type;
	private Timestamp requestTime;
	private Timestamp responseTime;

	private String networkStatus;
	private String meterId;

	private TransHistory retryTxHis;
	
	@ManyToOne
    @JoinColumn(name="RET_TXHIS_ID")
	public TransHistory getRetryTxHis() {
		return retryTxHis;
	}
	public void setRetryTxHis(TransHistory retryTxHis) {
		this.retryTxHis = retryTxHis;
	}
	@Column(name = "NETWORK_STATUS")
	public String getNetworkStatus() {
		return networkStatus;
	}
	public void setNetworkStatus(String networkStatus) {
		this.networkStatus = networkStatus;
	}
	@Column(name = "METER_ID")
	public String getMeterId() {
		return meterId;
	}
	public void setMeterId(String meterId) {
		this.meterId = meterId;
	}

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name = "TX_HISTORY_ID")
	public Integer getTxHistoryId() {
		return txHistoryId;
	}
	public void setTxHistoryId(Integer txHistoryId) {
		this.txHistoryId = txHistoryId;
	}
	
	@Column(name = "RECORD_TIME")
	public Timestamp getRecordTime() {
		return recordTime;
	}
	public void setRecordTime(Timestamp recordTime) {
		this.recordTime = recordTime;
	}
	
	@Column(name = "TX_ID")
	public String getTxId() {
		return txId;
	}
	public void setTxId(String txId) {
		this.txId = txId;
	}

	@Column(name = "TYPE")
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	
	@Column(name = "REQUEST_TIME")
	public Timestamp getRequestTime() {
		return requestTime;
	}
	public void setRequestTime(Timestamp requestTime) {
		this.requestTime = requestTime;
	}
	
	@Column(name = "RESPONSE_TIME")
	public Timestamp getResponseTime() {
		return responseTime;
	}
	public void setResponseTime(Timestamp responseTime) {
		this.responseTime = responseTime;
	}
	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((recordTime == null) ? 0 : recordTime.hashCode());
		result = prime * result
				+ ((requestTime == null) ? 0 : requestTime.hashCode());
		result = prime * result
				+ ((responseTime == null) ? 0 : responseTime.hashCode());
		result = prime * result
				+ ((txHistoryId == null) ? 0 : txHistoryId.hashCode());
		result = prime * result + ((txId == null) ? 0 : txId.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TransHistory other = (TransHistory) obj;
		if (recordTime == null) {
			if (other.recordTime != null)
				return false;
		} else if (!recordTime.equals(other.recordTime))
			return false;
		if (requestTime == null) {
			if (other.requestTime != null)
				return false;
		} else if (!requestTime.equals(other.requestTime))
			return false;
		if (responseTime == null) {
			if (other.responseTime != null)
				return false;
		} else if (!responseTime.equals(other.responseTime))
			return false;
		if (txHistoryId == null) {
			if (other.txHistoryId != null)
				return false;
		} else if (!txHistoryId.equals(other.txHistoryId))
			return false;
		if (txId == null) {
			if (other.txId != null)
				return false;
		} else if (!txId.equals(other.txId))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "TransactionHistory ["
				+ (txHistoryId != null ? "txHistoryId=" + txHistoryId + ", "
						: "")
				+ (recordTime != null ? "recordTime=" + recordTime + ", " : "")
				+ (txId != null ? "txId=" + txId + ", " : "")
				+ (type != null ? "type=" + type + ", " : "")
				+ (requestTime != null ? "requestTime=" + requestTime + ", "
						: "")
				+ (responseTime != null ? "responseTime=" + responseTime : "")
				+ "]";
	}
	
	
}
